package com.zzty.txj.serviceImpl;


import com.github.pagehelper.PageHelper;
import com.zzty.txj.dao.QuestionMapper;
import com.zzty.txj.entity.Question;
import com.zzty.txj.service.QuestionService;
import com.zzty.txj.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    QuestionMapper questionMapper;

    public boolean add(Question question) {
        boolean result = false;
       Integer count = questionMapper.add(question);
       if(count==1){
           result =true;
       }
        return result;
    }


    public int getId() {
        Integer id = questionMapper.getId();
        return id;
    }


    public Question getContent(int id) {
        Question question = questionMapper.getContent(id);
        System.out.println("question=="+question);
        return question;
    }


    public List<Question> getQuestions() {
        List<Question>questions = questionMapper.getQuestions();
        return questions;
    }

    @Override
    public List<Question> findUserModelByPage(int currentPage, int pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize);
        List<Question> allItems = questionMapper.getQuestions();    //全部记录
        int countNums = allItems.size();            //总记录数
        PageBean<Question> pageData = new PageBean<>(currentPage, pageSize, countNums);
        pageData.setItems(allItems);
        return pageData.getItems();
    }

    @Override
    public Integer getCount() {
        Integer count = questionMapper.getQuestions().size();
        return count;
    }

}
